package com.fbs.wowo.finance.util;

public class Base62 {
    private static String BASE_62_CHAR = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static int BASE = 62;

    public static String fromBase10(long dec) {
        StringBuilder sb = new StringBuilder("");
        if (dec == 0) {
            return "a";
        }
        while (dec > 0) {
            dec = fromBase10(dec, sb);
        }
        return sb.reverse().toString();
    }

    private static long fromBase10(long i, final StringBuilder sb) {
        int rem = (int)(i % BASE);
        sb.append(BASE_62_CHAR.charAt(rem));
        return i / BASE;
    }
}
